﻿/*
 * MerchandiseAlertDAL.cs
 * 描述：商品各种类型报警
 * JF 2011-10-09
 * 
 * Date
 * 
 * 
 * 
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EShop.Common;

namespace EShop.DAL
{
    public class MerchandiseAlertDAL:BaseDAL
    {
        /// <summary>
        /// 查询濒临低量的商品
        /// </summary>
        /// <param name="Barcode"></param>
        /// <param name="iType"></param>
        /// <returns></returns>
        public DataTable MerchandiseStockLowAlert(string Barcode, int iType)
        {
            string strUSP = "USP_MerchandiseAlterNumCheck";
            try
            {
                DataTable dt = new DataTable();
                if (iType < 2)
                {
                    SqlParameter parameter = new SqlParameter("@Type", iType);
                    dt = DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, parameter).Tables[0];
                }
                else
                {
                    SqlParameter[] parameter = {
                                               new SqlParameter("@Type", iType),
                                               new SqlParameter("@Barcode",Barcode)
                                           };
                    dt = DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, parameter).Tables[0];
                }
                return dt;
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }

        /// <summary>
        /// 修改商品低量报警设置
        /// </summary>
        /// <param name="strBarcode"></param>
        /// <param name="byteIsAlert"></param>
        /// <param name="iAlertNum"></param>
        /// <returns></returns>
        public int UpdateStockLowAlertStatus(string strBarcode, byte byteIsAlert, int iAlertNum)
        {
            string strUSP = "USP_MerchandiseAlterStatus_Update";
            try
            {
                SqlParameter[] parmeter ={
                                        new SqlParameter("@Barcode",SqlDbType.VarChar,30),
                                        new SqlParameter("@IsAlert",SqlDbType.Bit),
                                        new SqlParameter("@AlertNum",SqlDbType.Int)
                                    };
                parmeter[0].Value = strBarcode;
                parmeter[1].Value = byteIsAlert;
                parmeter[2].Value = iAlertNum;
                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parmeter);
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }

        /// <summary>
        /// 商品逾期报警
        /// </summary>
        /// <param name="iAlertEarlierDay">提前报警时间</param>
        /// <returns></returns>
        public DataTable MerchandiseOverTimeAlert(int iAlertEarlierDay)
        {
            string strUSP = "USP_MerchandiseOverTimeCheck";
            try
            {
                SqlParameter parameter = new SqlParameter("@AlertEarlierDay", iAlertEarlierDay);
                return DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, parameter).Tables[0];
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }

    }
}
